<%@page import="java.io.OutputStream"%>
<%@page import="java.io.FileNotFoundException"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
<% 
//打开指定文件的流信息  
String rootPath = request.getRealPath("\\");
String filepath = rootPath+request.getParameter("attAddress");
        System.out.println(filepath);
        File tempFile =new File( filepath.trim());  
  
        String fileName1= tempFile.getName(); 
 
        String fileName= fileName1.substring(fileName1.indexOf(".")+1);
        System.out.println(fileName);

FileInputStream fs = null; 
try { 
fs = new FileInputStream(new File(filepath)); 
}catch(FileNotFoundException e) { 
e.printStackTrace(); 
return; 
} 
//设置响应头和保存文件名 
response.reset(); 
response.setContentType("application/vnd.ms-excel"); 
 response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
//写出流信息 
int b = 0; 
try { 
OutputStream ops = response.getOutputStream(); 
while((b=fs.read())!=-1) { 
ops.write(b); 
} 
fs.close(); 
out.clear(); 
out = pageContext.pushBody(); 
}catch(Exception e) { 
e.printStackTrace(); 
System.out.println("下载文件失败!"); 
} 

%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 
  - Author(s): ThinkPad
  - Date: 2018-04-10 09:27:36
  - Description:
-->
<head>
<title>Title</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="<%= request.getContextPath() %>/common/nui/nui.js" type="text/javascript"></script>
    
</head>
<body>



	<script type="text/javascript">
    	nui.parse();
    </script>
</body>
</html>